import Taro from "@tarojs/taro"
import { ExpertAppointmentTimesProps, ExpertProps } from "./expert"

// ?预约详情
export enum OrderStatus { // ? 0=待预约 1=已预约 2=已作废 3=已完成
    '待预约' = 0,
    '已预约' = 1,
    '已作废' = 2,
    '已完成' = 3,
}
export type OrderProps = {
    beans: number
    create_time: string
    expert_id: number
    id: number
    no: string
    code: string
    left_time: number
    complete_time: string
    refund_status: 0 | 1
    remark: string
    star: number
    user_estimate: string //用户评价
    points: number
    status: OrderStatus
    success_time: string
    am_date: string
    time: ExpertAppointmentTimesProps["list"][0],
    time_data: ExpertAppointmentTimesProps[]
    times: string
    user_id: number
    suggest: string     //专家建议
    user_name: string
    user_company: string
    expert: ExpertProps //专家信息
}

export function OrderDetail(params: {
    id: number | string
}) {
    return Taro.request({
        url: `/api/order/detail`,
        method: 'POST',
        data: params
    }).then<OrderProps>
        (res => res?.data)
}

// ?取消预约
export function OrderCancel(params: {
    id: number | string
}) {
    return Taro.request({
        url: `/api/order/cancel`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}


// ?充值订单
export function OrderChargeList() {
    return Taro.request({
        url: `/api/order/chargeList`,
        method: 'GET',
    }).then<{
        beans: number
        charge_id: number
        check_remark: string
        check_time: string
        check_uid: string
        create_time: string
        id: number
        no: string
        img: string
        points: number
        remark: string
        type: number
        user_id: Number
        status: 0 | 1 | 2 // 0 = 申请中， 1 = 通过 2= 驳回
    }[]>(res => res?.data)
}



// ?预约咨询订单
export type OrderAppointmentListrProps = {
    address: string
    appoint_time: string
    beans: number
    cancel_user: number
    code: string
    create_time: string
    expert_id: number
    id: number
    no: string
    name: string
    points: number
    remark: string
    scene_id: number
    star: number
    status: OrderStatus
    success_time: string
    suggest: string
    times: string
    user_id: number
    user_estimate: string //用户评价
}
export function OrderAppointmentList(params: {
    type: 1 | 2 // ?1：咨询订单 2: 服务订单
}) {
    return Taro.request({
        url: `/api/order/appointmentList`,
        method: 'GET',
        data: params
    }).then<OrderAppointmentListrProps[]>(res => res?.data)
}

// ?活动订单
export type OrderEventListProps = {
    beans: number
    cancel_user: number
    code: string
    create_time: string
    event_id: number
    event_name: string
    id: number
    no: string
    status: 1 | 0 | 2 // ? 0=待核销，1=已核销，2=已取消',
    user_id: number
}
export function OrderEventList() {
    return Taro.request({
        url: `/api/order/eventList`,
        method: 'GET',
    }).then<OrderEventListProps[]>(res => res?.data)
}

// ?提交定制化咨询
export function OrderDiyAppointment(params: {
    expertId: number
    remark?: string
}) {
    return Taro.request({
        url: `/api/order/diyAppointment`,
        method: 'POST',
        data: params
    }).then<{
        beans: number
        cancel_user: number
        code: string
        create_time: string
        event_id: number
        event_name: string
        id: number
        status: 0 | 1
        user_id: number
    }[]>(res => res?.data)
}

// ?获取定制咨询订单
export function OrderDiyList() {
    return Taro.request({
        url: `/api/order/diyList`,
        method: 'POST',
    }).then(res => res?.data)
}

// ?用户评价
export function OrderRecommend(params: {
    star: number
    id: number
    msg: string
}) {
    return Taro.request({
        url: `/api/order/recommend`,
        method: 'POST',
        data: params
    }).then(res => res?.data)
}


// ?订单状态红点
export function OrderCount() {
    return Taro.request({
        url: `/api/order/count`,
        method: 'POST',
    }).then<{
        appoint: number
        charge: number
        event: number
        scene: number
    }>(res => res?.data)
}